const Koa = require('koa')
const app = new Koa()
const initRouter = require('./router/index');
const views = require("koa-views");
const serv = require('koa-static');
const koaBody = require('koa-body');
const path = require('path');

app.use(koaBody());
app.use(require('./plugins/cros'));
app.use(require('./plugins/token'));
app.use(require('./plugins/params'));

// 设置模版引擎
app.use(views(path.join(__dirname, "views"), {
  map: {
    html: 'underscore'
  }
}));

app.use(serv(__dirname + '/public'));

// 初始化路由
initRouter(app);

app.listen(4000, () => {
  console.log('服务已启动，在 http://localhost:4000/');
});
